#include <ros/ros.h>
#include "executor/chassis_executor.h"
#include "executor/gimbal_executor.h"
#include "behavior_tree/behavior_node.h"
#include "behavior_tree/behavior_tree.h"

#include "example_behavior/aim_behavior.h"
#include "example_behavior/attack_behavior.h"
#include "example_behavior/back_boot_area_behavior.h"//go 0 0 0
#include "example_behavior/bfs_search.h"
#include "example_behavior/blood_behavior.h"
#include "example_behavior/buff_behavior.h"
#include "example_behavior/chase_behavior.h"
#include "example_behavior/circle_behavior.h"
#include "example_behavior/dance_behavior.h"
#include "example_behavior/escape_behavior.h"
#include "example_behavior/gimbal_aim_behavior.h"
#include "example_behavior/gimbalget0_behavior.h"
#include "example_behavior/goal_behavior.h"
#include "example_behavior/gogoal_behavior.h"
#include "example_behavior/patrol_behavior.h"
#include "example_behavior/search_behavior.h"
#include "example_behavior/shake_behavior.h"
#include "example_behavior/under_attack_behavior.h"
#include "example_behavior/wait_behavior.h"
#include "example_behavior/recovery.h"
#include "roborts_msgs/FricWhl.h"
#include <iostream>

void param_init(ros::NodeHandle& p){}

int main(int argc, char **argv){
    ros::init(argc, argv, "behavior_test_node");
	std::string full_path = ros::package::getPath("roborts_decision") + "/config/decision.prototxt";
	ros::NodeHandle nh_p("~") ;
	param_init(nh_p);
    auto blackboard_ptr_ = std::make_shared<roborts_decision::Blackboard>(full_path);
    roborts_decision::Blackboard* blackboard = &*blackboard_ptr_;
    auto bfs_search = new roborts_decision::BfsSearch(blackboard);
    auto chassis_executor_ptr_ = std::make_shared<roborts_decision::ChassisExecutor>();
    chassis_executor_ptr_->Set_Search(bfs_search);//
    auto gimbal_executor_ptr_ = std::make_shared<roborts_decision::GimbalExecutor>();
    auto recovery_action_=std::make_shared<roborts_decision::RecoveryAction>(chassis_executor_ptr_, blackboard_ptr_);
    auto patrol_action_ = std::make_shared<roborts_decision::PatrolAction>(blackboard_ptr_, chassis_executor_ptr_);
    auto recovery_condition_=std::make_shared<roborts_decision::PreconditionNode>("recovery condition", blackboard_ptr_, [&](){
        return !blackboard_ptr_->ifCurrentValid();
    }, roborts_decision::AbortType::BOTH);
    recovery_condition_->SetChild(recovery_action_);
    auto root_selector_ = std::make_shared<roborts_decision::SelectorNode>("root",blackboard_ptr_);
    root_selector_->AddChildren(recovery_condition_);
    root_selector_->AddChildren(patrol_action_);
    roborts_decision::BehaviorTree root(root_selector_,100);
    //ros::service::waitForService("cmd_fric_wheel");
    ros::NodeHandle n;
    //ros::ServiceClient client = n.serviceClient<roborts_msgs::FricWhl>("cmd_fric_wheel");
    //roborts_msgs::FricWhl Fric;
    //Fric.request.open = true;
        //if(!client.call(Fric))
      //ROS_ERROR("FRICWHEEL NOT OPEN");
    root.Run();
    return 0;
}